/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Downloader;

import Downloader.CoreDownloader;
import Downloader.Ficheiro;
import java.net.MalformedURLException;

/**
 *
 * @author Gilberto Pereira <1040942@isep.ipp.pt>
 */
public class Downloader {

    private Ficheiro file = new Ficheiro();
    private CoreDownloader cd = new CoreDownloader();

    public void Downloader(String url, String pathLocal, int nivelMax) {
        try {
            DownloadPrivate(url, pathLocal, nivelMax);
        } catch (MalformedURLException ex) {
        }

    }

    private void DownloadPrivate(String url, String pathLocal, int nivelMax) throws MalformedURLException {
        int temp = -1;
        try {
            temp = cd.coreDownloadFile(url, pathLocal, nivelMax);
            //no caso de tudo ok com o url temp=0
        } catch (MalformedURLException ex) {
        }
        
        if (temp == 0) {
            this.file.setCaminholocal(cd.getFullLocalPathFile());
            this.file.setCaminhosite(cd.getFullWebPath());
            this.file.setDominio(cd.getHost());
            this.file.setFicheiro(cd.getFileName());
            this.file.setNiveis(cd.getNivel());
            this.file.setTamanhosite(cd.getSize());
        }
    }

    public void DownloadFile() {
        cd.downloadFile();
    }

    public Ficheiro getFicheiro() {
        return this.file;
    }
}
